<? require("adm_header.php"); ?>

<? writeCommonAdminTable("Payment Editor",1); ?>

<b>Here you can create payment packages for your members.</b><br>

<?
$_SESSION["v"]=1;
if (!$_SESSION["v"])
{
	echo "<p><font color='red'><b>Not in use</b></font><br />";
	echo "Since you are running a non-commercial version of the program, you can't use commercial functions like this.</p>";
}	

$tplPackages = new tplLoad();

$sql="select count(pid) as num from $pkg_tbl";
$res_count=q($sql);
$row_c=mysql_fetch_array($res_count);
$num_packages=$row_c["num"];
	
// Create new admin user if admin table is empty
if ($num_packages<1)
{
	q("INSERT INTO `$pkg_tbl` (`pid`, `pname`, `pterm`, `pdur`, `pactive`, `pprice`, `pcurrency`, `pupload`, `pmessages`, `pchat`, `pgb`, `protation`, `pvisitor`, `pfav`, `pmatch`, `pflirts`) VALUES (99, 'Default', 1, 3, 2, 0.00, 'USD', 3, 4, 999, 1, 1, 10, 10, 10, 10)");
	q("INSERT INTO `$pkg_tbl` (`pid`, `pname`, `pterm`, `pdur`, `pactive`, `pprice`, `pcurrency`, `pupload`, `pmessages`, `pchat`, `pgb`, `protation`, `pvisitor`, `pfav`, `pmatch`, `pflirts`) VALUES (1, 'Small', 2, 30, 1, 10.00, 'USD', 5, 20, 999, 1, 1, 1, 30, 30, 30)");
	q("INSERT INTO `$pkg_tbl` (`pid`, `pname`, `pterm`, `pdur`, `pactive`, `pprice`, `pcurrency`, `pupload`, `pmessages`, `pchat`, `pgb`, `protation`, `pvisitor`, `pfav`, `pmatch`, `pflirts`) VALUES (2, 'Medium', 1, 60, 1, 25.00, 'USD', 25, 250, 999, 1, 1, 55, 55, 55, 55)");
	q("INSERT INTO `$pkg_tbl` (`pid`, `pname`, `pterm`, `pdur`, `pactive`, `pprice`, `pcurrency`, `pupload`, `pmessages`, `pchat`, `pgb`, `protation`, `pvisitor`, `pfav`, `pmatch`, `pflirts`) VALUES (3, 'Gold', 1, 90, 1, 60.00, 'USD', 200, 200, 999, 1, 1, 200, 200, 200, 200)");
	
}




if (!$_SESSION["v"])
	$set_demo=1;

if (getParam("del",""))
{
	if (getParam("pid","")!=99)
	{
		$tplPackages->assign("message","Sure to delete, this plan can be in use? <a href='?pid=".getParam("pid","")."&del=1&confirm=1'>Yes, delete</a>");
	
		if ($set_demo)
		{
			echo "<p>System in demo mode, no deletion!</p>";	
		}
		elseif (getParam("del","") && getParam("confirm","") && !$set_demo)
		{
			$sql = "delete from $pkg_tbl where pid=" . getParam("pid","");
			$res = q($sql);
			$tplPackages->assign("message","Plan Deleted");
	
		}
	}
	else 
		$tplPackages->assign("message","This plan can not deleted, as it is a default required system package. Deleting would cause errors.");
	
}

if (getParam("submit","") AND (getParam("update","")==""))
{
	if ($set_demo)
	{
		echo "<p>System in demo mode, no deletion!</p>";	
	}
	else 
	{
	$sql = "insert into $pkg_tbl (pname,pterm,pdur,pactive,pprice,pcurrency,pupload,pmessages,pchat,pgb,protation,pvisitor,pfav,pmatch,pflirts,ppremium,mainType,concesionaria,avisos) values
	(
	'".getParam("pname","")."',
	'".getParam("pterm","")."',
	'".getParam("pdur","")."',
	'".getParam("pactive","")."',
	'".getParam("pprice","")."',
	'".getParam("pcurrency","")."',
	'".getParam("pupload","")."',	
	'".getParam("pmessages","")."',
	'".getParam("pchat","")."',
	'".getParam("pgb","")."',
	'".getParam("protation","")."',	
	'".getParam("pvisitor","")."',
	'".getParam("pfav","")."',
	'".getParam("pmatch","")."',
	'".getParam("pflirts","")."',
	'".getParam("ppremium","")."',
	'".getParam("mainType","")."',	
	'".getParam("concesionaria","")."',
	'".getParam("avisos","")."'
	)";
	
	$res_1 = q($sql);
	$last_id=mysql_insert_id();
	$tplPackages->assign("message","Created Package #$last_id");	
	}
}

$sql = "select * from $pkg_tbl";
$res = q($sql);
$c=0;

while($row=mysql_fetch_assoc($res))
{
	$array[$c]["pname"]=$row["pname"];
	$array[$c]["pid"]=$row["pid"];
	$array[$c]["counter"]=$c;
	$c++;
}

$tplPackages->assign("package_list", $array);


if (getParam("pid",""))
{
	
	if ($set_demo)
	{
		echo "<p>System in demo mode, nothing saved!</p>";	
	}
	
	if (getParam("submit","") AND $set_demo!=1)
	{
		$sql= "update $pkg_tbl set ";
		$sql.="pname='".getParam("pname","")."',";
		$sql.="pterm='".getParam("pterm","")."',";
		$sql.="pdur='".getParam("pdur","")."',";
		$sql.="pactive='".getParam("pactive","")."',";
		$sql.="pprice='".getParam("pprice","")."',";
		$sql.="pcurrency='".getParam("pcurrency","")."',";
		$sql.="mainType='".getParam("mainType","")."',";
		$sql.="concesionaria='".getParam("concesionaria","")."',";
		$sql.="avisos='".getParam("avisos","")."',";
		
		$sql.="pmessages='".getParam("pmessages","")."',";
		$sql.="pchat='".getParam("pchat","")."',";
		$sql.="pgb='".getParam("pgb","")."',";
		$sql.="protation='".getParam("protation","")."',";
		$sql.="pvisitor='".getParam("pvisitor","")."',";
		$sql.="pfav='".getParam("pfav","")."',";
		$sql.="pmatch='".getParam("pmatch","")."',";
		$sql.="pflirts='".getParam("pflirts","")."',";
		$sql.="pupload='".getParam("pupload","")."',";
		$sql.="ppremium='".getParam("ppremium","")."'";
		$sql.= " where pid=" . getParam("pid","");
		$res = q($sql);
		
		$tplPackages->assign("message","Updated package with ID #" . getParam("pid",""));	
		
	}
	
	// Edit Mode
	$sql = "select * from $pkg_tbl where pid=" . getParam("pid","");
	$res = q($sql);
	$row=mysql_fetch_array($res);
	
	$tplPackages->assign("pid",$row["pid"]);	
	$tplPackages->assign("pname",$row["pname"]);	
	$tplPackages->assign("pterm",$row["pterm"]);	
	$tplPackages->assign("pdur",$row["pdur"]);	
	$tplPackages->assign("pactive",$row["pactive"]);	
	$tplPackages->assign("pprice",$row["pprice"]);	
	$tplPackages->assign("pcurrency",$row["pcurrency"]);	
	$tplPackages->assign("pupload",$row["pupload"]);
	$tplPackages->assign("mainType",$row["mainType"]);
	$tplPackages->assign("concesionaria",$row["concesionaria"]);
	$tplPackages->assign("avisos",$row["avisos"]);
	
	$tplPackages->assign("pmessages",$row["pmessages"]);	
	$tplPackages->assign("pchat",$row["pchat"]);	
	$tplPackages->assign("pgb",$row["pgb"]);	
	$tplPackages->assign("protation",$row["protation"]);	
	$tplPackages->assign("pvisitor",$row["pvisitor"]);	
	$tplPackages->assign("pfav",$row["pfav"]);	
	$tplPackages->assign("pmatch",$row["pmatch"]);	
	$tplPackages->assign("pflirts",$row["pflirts"]);	
	$tplPackages->assign("ppremium",$row["ppremium"]);	
	$tplPackages->assign("update",1);	
	$tplPackages->assign("pid",getParam("pid",""));		
	
}



$tplPackages->display("adm_packages.tpl");
writeCommonAdminTable("Payment Editor","");
require("adm_footer.php"); ?>